<?php
	class Mindex extends CI_Model{
		protected $_table 			= "tbl_config";
		protected $_category 		= "tbl_category";
		protected $_subcategory 	= "tbl_subcategory";
		protected $_news 			= "tbl_news";
		protected $_support 		= "tbl_support";
		protected $_setup 			= "tbl_setup";
		protected $_product 		= "tbl_products";
		protected $_popup 			= "tbl_popup";
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function get_setup(){
			$this->db->where("set_id","1");
			return $this->db->get($this->_setup)->row_array();
		}
		public function getdata(){
			$this->db->where("config_id","1");
			return $this->db->get($this->_table)->row_array();
		}
		public function get_popup(){
			$this->db->where("pop_id","1");
			return $this->db->get($this->_popup)->row_array();
		}
		public function list_pro_saleoff($off){
			$this->db->where("pro_status","1");
			$this->db->where("pro_saleoff","1");
			$this->db->order_by("pro_id","DESC");
			$this->db->limit($off);
			return $this->db->get($this->_product)->result_array();
		}
		public function list_pro_new($off){
			$this->db->where("pro_status","1");
			$this->db->where("pro_new","1");
			$this->db->order_by("pro_id","DESC");
			$this->db->limit($off);
			return $this->db->get($this->_product)->result_array();
		}
		public function list_pro_bestsale($off){
			$this->db->where("pro_status","1");
			$this->db->where("pro_bestsale","1");
			$this->db->order_by("pro_id","DESC");
			$this->db->limit($off);
			return $this->db->get($this->_product)->result_array();
		}
		public function list_pro_hot($off){
			$this->db->where("pro_status","1");
			$this->db->where("pro_hot","1");
			$this->db->order_by("pro_id","DESC");
			$this->db->limit($off);
			return $this->db->get($this->_product)->result_array();
		}
		public function list_news(){
			$this->db->order_by("news_id","DESC");
			$this->db->limit(4);
			return $this->db->get($this->_news)->result_array();
		}
		public function list_support(){
			$this->db->where("sup_status",1);
			$this->db->order_by("sup_id","DESC");
			return $this->db->get($this->_support)->result_array();
		}
		public function list_cate(){
			$this->db->where("cate_status",1);
			$this->db->where("cate_parent",1);
			$this->db->order_by("cate_order","DESC");
			return $this->db->get($this->_category)->result_array();
		}
		public function list_sub($cate_id){
			$this->db->where("cate_id_parent",$cate_id);
			$this->db->where("cate_parent",2);
			$this->db->order_by("cate_order","DESC");
			return $this->db->get($this->_category)->result_array();
		}
		public function listall(){
			$list = $this->list_cate();
			$data = array();
			if($list != NULL){
				foreach($list as $k => $v){
					$data[] = $this->list_sub($v['cate_id']);
				}
			}
			$ok = array(
				"cate" => $list,
				"sub" => $data
			);
			return $ok;
		}
	}